package com.letoy.study.controller;

import com.letoy.study.service.UserDetailsService;
import com.letoy.study.vo.UserDetailsVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;

/**
 * @author JiaTianLuo
 * @version 1.0
 * @date 2021/1/26 23:17
 */
@Controller
@Api(value = "用户信息表接口", tags = "用户信息表表API")
public class UserDetailsController {

    @Autowired
    private UserDetailsService userDetailsService;

    @PostMapping("/userDetails/receiveUserDetails")
    @ApiOperation(value = "接收时间信息", notes = "接收时间信息")
    @ResponseBody
    public HashMap<String, Object> receiveUserDetails(UserDetailsVo userDetailsVo) {
        HashMap<String, Object> map = new HashMap<>();
        map.put("res", userDetailsService.initializationUserDetails(userDetailsVo));
        return map;
    }

    @ApiOperation(value = "查询所有信息", notes = "查询所有信息")
    @PostMapping("/userDetails/findAll")
    @ResponseBody
    public HashMap findAll() {
        return userDetailsService.findAll();
    }

    @ApiOperation(value = "更新信息", notes = "更新信息")
    @PostMapping("/userDetails/changeUserDetails")
    @ResponseBody
    public HashMap changeUserDetails(@RequestBody UserDetails userDetails) {
        return userDetailsService.changeUserDetails((com.letoy.study.entity.UserDetails) userDetails);
    }

    @ApiOperation(value = "初始化信息", notes = "初始化信息")
    @PostMapping("/userDetails/initializationUserDetails")
    @ResponseBody
    public HashMap initializationUserDetails(UserDetailsVo userDetailsVo) {
        HashMap<String, Object> map = new HashMap<>();
        map.put("res", userDetailsService.initializationUserDetails(userDetailsVo));
        return map;
    }
}
